package self.hoy.demo.tof.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import self.hoy.demo.tof.entity.LayUiVo;
import self.hoy.demo.tof.entity.Menu;
import self.hoy.demo.tof.feign.MenuFeign;

import javax.annotation.Resource;
import java.util.List;

@Controller
//@RestController
@RequestMapping("/client")
public class ClientHandler {
    @Resource
    private MenuFeign menuFeign;

    @GetMapping("/findAll")
//    @GetMapping("/index/{index}/{limit}")
    @ResponseBody
//    public List<Menu> findAll(@PathVariable("index") Integer index, @PathVariable("limit") Integer limit) {
//    public List<Menu> findAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
//        int index = (page == null || page < 0 ? 0 : page - 1) * limit;
//        return menuFeign.findAll(index, limit);
//    }

    public LayUiVo<Menu> findAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        int index = (page == null || page < 0 ? 0 : page - 1) * limit;
        List<Menu> menuList = menuFeign.findAll(index, limit);
        return new LayUiVo<>(menuList);
    }

    /**
     * RestController会不会让String以字符串的形式返回？
     * @param location
     * @return
     */
    @GetMapping("/redirect/{location}")
    public String redirect(@PathVariable("location") String location) {
        return location;
    }
}
